ci: make per-package test matrix respect detect-changes#309
Open
OttoAllmendinger wants to merge 1 commit into
Open
ci: make per-package test matrix respect detect-changes#309OttoAllmendinger wants to merge 1 commit into
OttoAllmendinger wants to merge 1 commit into
Conversation
The `test` job's matrix used `package: ${{ fromJson(detect-changes) }}`
as the base plus a static `include:` block listing all 7 packages with
their per-package flags. Because GitHub Actions spawns a NEW matrix
combination for any `include:` entry whose `package` can't be merged
into the base (it would overwrite `package`), every package was
re-added as its own job on every PR — `detect-changes` shrunk the base
matrix but the `include` block immediately re-expanded it to all 7
packages. `Test wasm-privacy-coin` (and every other `Test <pkg>`) ran
on every PR regardless of what changed.
Move the per-package flags into `detect-changes.mjs`, which now emits
an array of objects [{package, needs-wasm-pack, has-wasm-pack-tests}]
filtered to changed packages, and consume it with
`matrix.include: ${{ fromJson(...) }}` (no base `package:` key, no
static list). Now only changed packages — plus the shared-infra and
empty-diff fallbacks, which return all packages — become test jobs.
Verified locally: for a PR touching only packages/wasm-utxo/,
detect-changes emits a single entry and the matrix would spawn only
`Test wasm-utxo` instead of all 7 `Test *` jobs.
The stable `test / Test` gate job (needs build/test/finalize) remains
the branch-protection check, and the non-PR / shared-infra / no-op
fallbacks keep the matrix non-empty so the gate is never skipped.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Every
Test <package>job ran on every PR, regardless of what changed. A PR touching onlypackages/wasm-utxo/still ranTest wasm-privacy-coin(and all 6 other package jobs).Root cause: the
testjob's matrix used a dynamic base (package: ${{ fromJson(detect-changes) }}) plus a staticinclude:block listing all 7 packages with their per-package flags. GitHub Actions spawns a new matrix combination for anyinclude:entry whosepackagecan't merge into the base (it would overwritepackage), so theincludeblock re-added every package as its own job — defeatingdetect-changes.Evidence: for PR #306 (head
8feac80a, onlypackages/wasm-utxo/files),Detect ChangesloggedPackages to test: ["wasm-utxo"], yet all 7Test *jobs ran.Fix
needs-wasm-pack,has-wasm-pack-tests) into.github/scripts/detect-changes.mjs, which now emits an array of objects[{package, needs-wasm-pack, has-wasm-pack-tests}]filtered to changed packages.matrix.include: ${{ fromJson(needs.detect-changes.outputs.packages) }}— no basepackage:key, no static list.Now only changed packages become test jobs. The non-PR / shared-infra (
.github/, rootpackage.json/lerna.json/package-lock.json) / no-op fallbacks still return all packages, so the matrix is never empty on PRs.Verification
Locally simulated the PR #306 scenario (
BASE_SHA=c744b64d HEAD_SHA=8feac80a):→ matrix would spawn only
Test wasm-utxoinstead of all 7. prettier clean. (actionlint not run locally — nix unavailable; the repo's CI flake check validates it.)Notes
test / Testgate job (needs: [build, test, finalize]) remains the branch-protection check; per-package jobs are not required to run individually.buildjob still builds all packages unconditionally (it produces one sharedbuild-outputartifact); this change only scopes the per-package test jobs. Makingbuildper-package is a larger refactor, intentionally out of scope.